import Mock from 'mockjs'

const List = []
const count = 100

const baseContent = '<p>I am testing data, I am testing data.</p><p><img src="https://wpimg.wallstcn.com/4c69009c-0fd4-4153-b112-6cb53d1cf943"></p>'
const image_uri = 'https://wpimg.wallstcn.com/e4558086-631c-425c-9430-56ffb46e70b3'

for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: '@increment',
    timestamp: +Mock.Random.date('T'),
    author: '@first',
    reviewer: '@first',
    title: '@title(5, 10)',
    content_short: 'mock data',
    content: baseContent,
    forecast: '@float(0, 100, 2, 2)',
    importance: '@integer(1, 3)',
    'type|1': ['CN', 'US', 'JP', 'EU'],
    'status|1': ['published', 'draft', 'deleted'],
    display_time: '@datetime',
    comment_disabled: true,
    pageviews: '@integer(300, 5000)',
    image_uri,
    platforms: ['a-platform']
  }))
}

export default [
  {
    url: '/article/list',
    type: 'get',
    response: config => {
      const { importance, type, title, page = 1, limit = 20, sort } = config.query

      let mockList = List.filter(item => {
        if (importance && item.importance !== +importance) return false
        if (type && item.type !== type) return false
        if (title && item.title.indexOf(title) < 0) return false
        return true
      })

      if (sort === '-id') {
        mockList = mockList.reverse()
      }

      const pageList = mockList.filter((item, index) => index < limit * page && index >= limit * (page - 1))

      return {
        code: 20000,
        data: {
          total: mockList.length,
          items: pageList
        }
      }
    }
  },

  {
    url: '/article/detail',
    type: 'get',
    response: config => {
      const { id } = config.query
      for (const article of List) {
        if (article.id === +id) {
          return {
            code: 20000,
            data: article
          }
        }
      }
    }
  },

  {
    url: '/article/pv',
    type: 'get',
    response: _ => {
      return {
        code: 20000,
        data: {
          pvData: [
            { key: 'PC', pv: 1024 },
            { key: 'mobile', pv: 1024 },
            { key: 'ios', pv: 1024 },
            { key: 'android', pv: 1024 }
          ]
        }
      }
    }
  },

  {
    url: '/article/create',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/article/update',
    type: 'post',
    response: _ => {
      return {
        code: 20000,
        data: 'success'
      }
    }
  },

  {
    url: '/form/add',
    type: 'get',
    response: _ => {
      return {
        'httpCode': 200,
        'code': 20000,
        'message': null,
        'data': [{
          'id': 1,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id1',
          'discernName': 'id1',
          'showName': '文本',
          'columnTypeId': 1,
          'editTypeId': 1,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': '1234',
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 1,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': 'max:7|min:1|validator:05',
          'backendLabel': '请输入内容',
          'remark': null,
          'columnTypeIdStr': 'int',
          'editTypeIdStr': '文本'
        },
        {
          'id': 2,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id2',
          'discernName': 'id2',
          'showName': '下拉菜单',
          'columnTypeId': 1,
          'editTypeId': 2,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': null,
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 1,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': 'region',
          'backendLabel': '请选择',
          'remark': null,
          'columnTypeIdStr': 'int',
          'editTypeIdStr': '文本'
        },
        {
          'id': 3,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id3',
          'discernName': 'id3',
          'showName': '单选',
          'columnTypeId': 1,
          'editTypeId': 3,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': 1,
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 1,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': 'resource',
          'backendLabel': '请选择',
          'remark': null,
          'columnTypeIdStr': 'int',
          'editTypeIdStr': '文本'
        },
        {
          'id': 4,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id4',
          'discernName': 'id4',
          'showName': '复选（已修复）',
          'columnTypeId': 1,
          'editTypeId': 4,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': [1, 2],
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 1,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': 'type',
          'backendLabel': '',
          'remark': null,
          'columnTypeIdStr': 'int',
          'editTypeIdStr': '文本'
        },
        {
          'id': 5,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id5',
          'discernName': 'id5',
          'showName': '下拉菜单（带搜索）',
          'columnTypeId': 1,
          'editTypeId': 7,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': null,
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 0,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': 'region',
          'backendLabel': '请选择',
          'remark': null,
          'columnTypeIdStr': 'int',
          'editTypeIdStr': '文本'
        },
        {
          'id': 6,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id6',
          'discernName': 'id6',
          'showName': '日期时间（当前时间，只读）',
          'columnTypeId': 1,
          'editTypeId': 9,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': '',
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 0,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': null,
          'backendLabel': '请选择日期',
          'remark': null,
          'columnTypeIdStr': 'datetime',
          'editTypeIdStr': '文本'
        },
        {
          'id': 7,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id7',
          'discernName': 'id7',
          'showName': '日期时间（选择）',
          'columnTypeId': 1,
          'editTypeId': 10,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': '',
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 0,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': 'date',
          'backendLabel': '请选择日期',
          'remark': null,
          'columnTypeIdStr': 'datetime',
          'editTypeIdStr': '克'
        },
        {
          'id': 8,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id8',
          'discernName': 'id8',
          'showName': '文本区',
          'columnTypeId': 1,
          'editTypeId': 11,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': '',
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 1,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': 'desc',
          'backendLabel': '备注',
          'remark': null,
          'columnTypeIdStr': 'datetime',
          'editTypeIdStr': '克'
        },
        {
          'id': 9,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id9',
          'discernName': 'id9',
          'showName': '密码区',
          'columnTypeId': 1,
          'editTypeId': 14,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': null,
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 1,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': 'password',
          'backendLabel': '请输入密码',
          'remark': null,
          'columnTypeIdStr': 'datetime',
          'editTypeIdStr': '克'
        },
        {
          'id': 10,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id10',
          'discernName': 'id10',
          'showName': '开关 (已修复)',
          'columnTypeId': 1,
          'editTypeId': 15,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': '1',
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 1,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': null,
          'backendLabel': '请选择日期',
          'remark': null,
          'columnTypeIdStr': 'datetime',
          'editTypeIdStr': '克'
        },
        {
          'id': 11,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id11',
          'discernName': 'id11',
          'showName': '下拉树',
          'columnTypeId': 1,
          'editTypeId': 17,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': [],
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 1,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': null,
          'backendLabel': '',
          'remark': null,
          'columnTypeIdStr': '',
          'editTypeIdStr': ''
        },
        {
          'id': 12,
          'menuId': 71,
          'tableName': null,
          'columnName': 'id12',
          'discernName': 'id12',
          'showName': '下拉树',
          'columnTypeId': 1,
          'editTypeId': 19,
          'dataGroupId': 69997,
          'columnGroupId': 1,
          'defaultValue': [],
          'isKey': 1,
          'isList': 1,
          'isAdd': 1,
          'isEdit': 1,
          'isSearch': null,
          'sortOrderList': 200,
          'sortOrderEdit': 200,
          'isRequired': 1,
          'isReadonly': 0,
          'isUnique': 0,
          'validateRule': null,
          'backendLabel': '',
          'remark': null,
          'columnTypeIdStr': '',
          'editTypeIdStr': ''
        }]
      }
    }
  },

  {
    url: '/form/fetchOptions',
    type: 'get',
    response: _ => {
      return {
        'httpCode': 200,
        'code': 20000,
        'message': null,
        'data': [{
          'id': 1,
          'groupNo': 69997,
          'name': '办公设备',
          'nameEn': null,
          'value': 1,
          'defaultFlag': null,
          'isAble': 1,
          'fInfo1': null,
          'fInfo2': null,
          'fInfo3': null,
          'fInfo4': 0,
          'fOrder': 1
        },
        {
          'id': 2,
          'groupNo': 69997,
          'name': '学习资料',
          'nameEn': null,
          'value': 2,
          'defaultFlag': null,
          'isAble': 1,
          'fInfo1': null,
          'fInfo2': null,
          'fInfo3': null,
          'fInfo4': 0,
          'fOrder': 2
        }]
      }
    }
  },
  {
    url: '/form/queryMenu',
    type: 'get',
    response: _ => {
      return {
        'httpCode': 200,
        'code': 20000,
        'message': null,
        'data': {
          'SysRuleMenu': {
            'menuUrl': '1234'
          }
        }
      }
    }
  },

  {
    url: '/form/createArticle',
    type: 'get',
    response: _ => {
      return {
        'httpCode': 200,
        'code': 20000,
        'message': null,
        'data': {}
      }
    }
  },

  {
    url: '/form/fetchTree',
    type: 'get',
    response: _ => {
      return {
        'httpCode': 200,
        'code': 20000,
        'message': null,
        'data': [{
          title: 'parent 1',
          expand: true,
          selected: false,
          id: 1,
          children: [
            {
              title: 'parent 1-1',
              expand: true,
              id: 2,
              children: [
                {
                  title: 'leaf 1-1-1',
                  disabled: true,
                  id: 11
                },
                {
                  title: 'leaf 1-1-2',
                  selected: true,
                  id: 12
                }
              ]
            },
            {
              title: 'parent 1-2',
              expand: true,
              id: 3,
              children: [
                {
                  title: 'leaf 1-2-1',
                  checked: true,
                  id: 13
                },
                {
                  title: 'leaf 1-2-1',
                  id: 14
                }
              ]
            }
          ]
        }]
      }
    }
  }
]

